{include file="admin@public/header"/}

<style>
	.ui-droplist-wrap .droplist .list-item:hover{background-color: #faffad;}
</style>

<div class="bill-ser-top">
	<ul class="ul-inline cf">
		<li>
			<input type="text" id="keyword" class="ui-input ui-input-ph" placeholder="请输入单据号或供应商或备注"
				style="width: 190px;font-size: 12px;">
		</li>
		<li>
			<label>日期:</label>
			<input type="date" id="startdate" class="ui-input " value="" style="width: 125px;">
			<i>-</i>
			<input type="date" id="enddate" class="ui-input " value="" style="width: 125px;">
		</li>

		<li>
			<div class="ui-btn-menu fl" id="filter-menu"> <span class="ui-btn menu-btn"> <span
						id="selected-date">退款状态</span><b></b> </span>
				<div class="con">
					<ul class="filter-list">
						<li>
							<input type="checkbox" name="hxState" value="未退款" class="vm" id="hxState_0"><label
								for="hxState_0">未退款</label>
							<input type="checkbox" name="hxState" value="部分退款" class="vm" id="hxState_1"><label
								for="hxState_1">部分退款</label>
							<input type="checkbox" name="hxState" value="全部退款" class="vm" id="hxState_2"><label
								for="hxState_2">全部退款</label>
						</li>
					</ul>
				</div>
			</div>
		</li>
		<li id="liConfirm">
			<div class="ui-btn-menu fl" id="filter-menu"> <span class="ui-btn menu-btn"> <span
						id="selected-confirm">对单状态:</span><b></b> </span>
				<div class="con">
					<ul class="filter-list">
						<li>
							<input type="checkbox" name="cfState" value="0" class="vm" id="cfState_0"><label
								for="cfState_0">未核对</label>
							<input type="checkbox" name="cfState" value="1" class="vm" id="cfState_1"><label
								for="cfState_1">已核对</label>
						</li>
					</ul>
				</div>
			</div>
		</li>
		<li id="li_check">
			<label>审核状态:</label>
			<span id="span_checked">
				<span class="ui-combo-wrap" style="width: 118px;">
					<input type="text" class="input-txt" autocomplete="off" readonly="readonly" id="state_type_name" value="空" style="cursor: default; width: 92px;">
					<span class="trigger" id="state_type_trigger"></span>
				</span>
			</span>
		  </li>
		<li><a class="mrb more ui-btn" id="moreCon" onclick="heightSearch('/admin/basic/hight_search.html?o_type={$o_type}','高级搜索','815px','460px')">高级搜索</a><a class="ui-btn mrb ui-btn-search" id="search">查询</a></li>
		<!-- <li class="url-box" id="openUrl"><a href="https://club.kingdee.com/club/newclub/school/course?product_id=7&amp;cid=1548#pid=5704" target="_blank" class="video-icon"></a>购货订单查询</li> -->
	</ul>
</div>

<!-- 审核状态 -->
{include file="admin@public/order/shenhe_state"/}


<div class="wrapper btc">
	<div class="bill-ser-botm">
		<div class="cf">
			<div class="ui-config-box">
				<span id="config" class="ui-config"><a href="#" class="ui-icon-config-new"></a>列设置</span>
			</div>
			<div class="fr">
				<a class="ui-btn-bill ui-btn-add" id="add" onclick="addPage('/scm/invRe/add.html','purchase','购货退货单')">新增</a>
				<div class="ui-btn-menu ml10">
					<a class="ui-btn-bill ui-btn-hl menu-btn mrb" style="width: 40px;padding-right: 14px;" href="#"
						id="shenhe">审核<b></b></a>
					<div class="con hl more-operate-con"
						style="margin-left: 0px;font-size: 14px;width: 55px;padding: 6px;">
						<ul class="more-operate cf" style="border-style:dashed; border-width:1px; border-color:#ccc;">
							<li><a href="#" id="reshenhe">反审核</a></li>
						</ul>
					</div>
				</div>
				<div class="ui-btn-menu ml10">
					<a class="ui-btn-bill ui-btn-hl menu-btn mrb" href="#" id="print" target="_blank">打印<b></b></a>
					<div class="con hl more-operate-con"
						style="margin-left: 0px;font-size: 14px;width: 54px;padding: 3px;">
						<ul class="more-operate cf" style="border-style:dashed; border-width:1px; border-color:#ccc;">
							<li style="padding-left: 8px;"><a href="#" id="printSet">设置</a></li>
						</ul>
					</div>
				</div>
				<div class="ui-btn-menu ml10">
					<a class="ui-btn-bill ui-btn-hl menu-btn mrb" style="width: 40px;padding-right: 7px;" href="#"
						id="import" target="_blank">导入<b></b></a>
					<div class="con hl more-operate-con"
						style="margin-left: 0px;font-size: 14px;width: 54px;padding: 3px;">
						<ul class="more-operate cf" style="border-style:dashed; border-width:1px; border-color:#ccc;">
							<li style="padding-left: 8px;"><a id="export">导出</a></li>
						</ul>
					</div>
				</div>
				<a href="#" class="ui-btn-bill ui-btn-hl ml10" id="del">删除</a>
				<div class="ui-btn-menu ml10" id="confirmBtns">
					<a class="ui-btn-bill ui-btn-hl menu-btn mrb"
						style="width: 50px;padding-right: 7px;padding-left: 23px;" href="#"
						id="dd">对单<b></b></a>
					<div class="con hl more-operate-con"
						style="margin-left: 0px;font-size: 14px;width: 74px;padding: 3px;">
						<ul class="more-operate cf" style="border-style:dashed; border-width:1px; border-color:#ccc;">
							<li style="padding-left: 8px;"><a href="#" id="redd">撤销对单</a></li>
						</ul>
					</div>
				</div>
			</div>
		</div>
	</div>
	<div class="grid-wrap">
		<table id="grid">
		</table>
		<div id="page"></div>
	</div>
</div>






<script type="text/javascript">
	//$(function(){
	$(document).ready(function () {
		

		// 获取当前日期
		var myDate = new Date;
		var year = myDate.getFullYear(); //获取当前年
		var mon = myDate.getMonth() + 1; //获取当前月
		var date = myDate.getDate(); //获取当前日
		// console.log(year + '-' + mon + '-' + date)
		if (mon < 10) {
			mon = "0" + mon;
		}
		if (date < 10) {
			date = "0" + date;
		}
		$("#startdate").val(year + '-' + mon + '-01');
		$("#enddate").val(year + '-' + mon + '-' + date);

		//alert("1111");
		$("#grid").jqGrid({
			url: '/scm/invre/index.html?ajax=100',
			datatype: "json",//数据来源，本地数据（local，json,jsonp,xml等）
			height: '90%',//高度，表格高度。可为数值、百分比或'auto'
			//width: Public.setGrid().w,
			//height: Public.setGrid().h,
			colNames: ["操作", "单据日期", "单据编号", "供应商", "关联购货订单号", "原购货单号", "原购货数量", "数量", "购货金额", "优惠后金额", "已退款", "退款状态", "对单状态", "制单人", "审核人", "备注", "打印次数", "id",'status','type'],
			colModel: [
				{ name: 'id', index: 'id', width: 70, formatter: actions },
				{ name: 'dj_time'  ,align:"center"},
				{ name: 'sn' ,align:"center" },
				{ name: 'customer_name', width: 200 },
				{ name: 'xhdd_sn', width: 200, lable:"关联购货订单号",formatter: xhdd_sn_formatter },
				{ name: 'xh_sn', width: 150, lable:"原购货单号" },
				{ name: 'xh_sn_num', width: 150, lable:"原购货数量" },
				{ name: 'shuliang', width: 80 ,align:"right" },
				{ name: 'before_yh_price', width: 100 ,align:"right"},
				{ name: 'yh_price', width: 105 ,align:"right"},
				{ name: 'payment', width: 100 ,align:"right"},
				{ name: 'pay_status_name', width: 80 ,align:"center"},
				{ name: 'dd_status_name', width: 80 ,align:"center" },
				{ name: 'add_user_name', width: 80 ,align:"center" },
				{ name: 'shenhe_user_name' , width: 80 ,align:"center"},
				{ name: 'mark', width: 200 },
				{ name: 'print_number', width: 80 ,align:"center" },
				{ name: 'id', hidden: true },
				{ name: 'status',hidden:true },
				{ name: 'type', hidden: true }
			],
			rowNum: 10,
			rowList: [10, 20, 30],
			sortname: 'id',
			sortorder: "desc",
			pagerpos: "left",//分页位置
			multiselect:true,  //自带复选框
			pgbuttons: true,//翻页按钮
			pagination: true,
			altRows: !0,
			gridview: !0,
			shrinkToFit: !1,
			cellLayout: 8,
			autowidth: !0,
			pager: "#page",
			viewrecords: !0,
			cmTemplate: {
				sortable: !1,
				title: !1
			},
			// 合计
			footerrow: true,
			gridComplete: function () {
				var numbers = parseFloat($("#grid").getCol('number', false, 'sum')).toFixed(2);
				var purchase_costs = parseFloat($("#grid").getCol('purchase_cost', false, 'sum')).toFixed(2);
				var after_discounts = parseFloat($("#grid").getCol('after_discount', false, 'sum')).toFixed(2);
				var payments = parseFloat($("#grid").getCol('payment', false, 'sum')).toFixed(2);
				$("#grid").footerData('set', { "supplier_name": '合计：', number: numbers, purchase_cost: purchase_costs, after_discount: after_discounts ,payment:payments});
				var grid = $("#grid");
				var col_hs = grid.getCol('col_h', false);//获取某一列
				var ids = grid.getDataIDs();
				var rowDatas = grid.jqGrid("getRowData");//获取所有行的数据
				//alert(col_hs);
				for (var i = 0; i < ids.length; i++) {
					//设置行高
					grid.setRowData(ids[i], false, { height: 40 * col_hs[i] });
					var rowData = rowDatas[i];
					if (rowData.status == "0") {
						$("#" + ids[i] + " td").css("color", "#999999");
					}else{
						$("#" + ids[i] + " td").css("color", "#ff0000");
					}
				}
			},
			loadError: function (t, e, i) {
				parent.Public.tips({
					type: 1,
					content: "操作失败了哦，请检查您的网络链接！"
				})
			},
			//双击表格行事件
			ondblClickRow: function (row) {
				var rowData = $('#grid').jqGrid('getRowData', row);
				parent.tab.addTabItem({
					tabid: "purchaseinvRe",
					text: "购货退货单",
					url: "/scm/invre/edit.html?id=" + rowData.id,
				})
			}
		});
	});

	function cLink(cellvalue, options, rowObject) {
		console.log(rowObject.status);
		if (rowObject.status == 0) {
			return '<span class="set-status open" data-delete="false" onclick="switchs(this,' + rowObject.id + ')"><span class="ui-icon-circle"></span></span>';
		} else {
			return '<span class="set-status close" data-delete="false" onclick="switchs(this,' + rowObject.id + ')"><span class="ui-icon-circle"></span></span>';
		}

	}

	function xhdd_sn_formatter(cellvalue, options, rowObject) {
		if (rowObject.xhdd_sn==null) {
			rowObject.xhdd_sn='';
		}
		return '<a style="color: inherit;" onclick="addPage('+'\'/scm/invpo/edit.html?id='+rowObject.xhdd_id+'\',\'purchase-purchase2\',\'购货订单\')">'+ rowObject.xhdd_sn +'</a>';
	}

	function actions(cellvalue, options, rowObject) {
		return '<div class="operating"><span class="ui-icon ui-icon-pencil" onclick="edit(' + rowObject.id + ')">修改</span> <span class="ui-icon ui-icon-trash" onclick="del(' + rowObject.id + ')">删除</span></div>';
	}

	function edit(id) {
		parent.tab.addTabItem({
			tabid: "purchaseinvRe",
			text: "购货退货单",
			url: "/scm/invre/edit.html?id=" + id,
		})
	}

	function switchs(obj, id) {
		if ($(obj).hasClass("open")) {
			$(obj).removeClass("open");
			$(obj).addClass("close");
			status = 1;
		} else {
			$(obj).removeClass("close");
			$(obj).addClass("open");
			status = 0;
		}

		$.ajax({
			type: 'POST',
			url: "save.html",
			data: { id: id, status: status },
			dataType: "json",
			async: false,
			error: function (request) {
				layer.msg("发送请求失败！");
			},
			success: function (data) {
				if (data.status == 1) {
					layer.msg(data.msg);
				} else {
					layer.msg(data.msg);
				}

			}
		});
	}
</script>


<script type="text/javascript">
	//$action_type 0 查询 1 导出
	function grid_search_list($action_type){
		var startdate = $('#startdate').val();
		var enddate = $('#enddate').val();
		var keyword = $('#keyword').val();//关键字

		var hxState=document.getElementsByName('hxState'); 
		//获取付款状态
		var str=''; 
		for(var i=0; i<hxState.length; i++){ 
			if(hxState[i].checked) str+=hxState[i].value+','; //如果选中，将value添加到变量s中 
		} 
		var pay_status_name=str.slice(0, -1);//订单状态

		//获取对单状态
		var obj=document.getElementsByName('cfState'); 
		var str=''; 
		for(var i=0; i<obj.length; i++){ 
			if(obj[i].checked) str+=obj[i].value+','; //如果选中，将value添加到变量s中 
		} 
		var dd_status=str.slice(0, -1);//订单状态

		var state_id=$("#state_type_id").val();//审核状态

	
		$("div.grid-subtitle").text("日期: " + startdate + " 至 " + enddate);


		if ($action_type==0) {
			var param={ 'ajax': '100', 'startdate': startdate, 'enddate': enddate, 'keyword': keyword,'state_id':state_id,'pay_status_name':pay_status_name,dd_status:dd_status};  //发送数据
		}else if($action_type==1){
			var param={'is_export':1,'ajax': '100', 'startdate': startdate, 'enddate': enddate, 'keyword': keyword,'state_id':state_id,'pay_status_name':pay_status_name,dd_status:dd_status}
			var export_param='';
			for(let key  in param){
				export_param+=key+'='+ param[key]+'&';
			}
			export_param = export_param.substr(0, export_param.length - 1);  
			//console.log(export_param);
			window.location.href="index.html?"+export_param;
			return false;
		}
	
		

		//此处可以添加对查询数据的合法验证 
		$("#grid").jqGrid('setGridParam', {
			datatype: 'json',
			postData: param, //发送数据 
			page: 1
		}).trigger("reloadGrid"); //重新载入 

	}
	
	$(document).ready(function () {
		// 导出按钮
		$("#export").click(function () {
			grid_search_list(1);//0 查询 1 导出
		});

		// 点击查询按钮
		$("#search").click(function () {
			grid_search_list(0);//0 查询 1 导出
		});
	});
</script>

<script type="text/javascript">
  $(document).ready(function () {
    // 审核按钮
    $("#shenhe").click(function () {
    	//alert("1111111");
      	var ids = $("#grid").jqGrid('getGridParam','selarrrow');

		if (ids == '' || ids == null) {
			layer.msg('请先选择需要审核的项！');
			return false;
		}
		//获取商品信息
		$.post('shenhe.html', { ids: ids, status: 1,type:1}, function (res) {
			layer.msg(res.msg);
			if (res.status == 1) {
				reload();
			}
		});
    })

    // 反审核按钮
    $("#reshenhe").click(function () {
    	var ids = $("#grid").jqGrid('getGridParam','selarrrow');
      	if (ids == '' || ids == null) {
			layer.msg('请先选择需要反审核的项！');
			return false;
		}
		//获取商品信息
		$.post('shenhe.html', { ids: ids, status: 0,type:2 }, function (res) {
			layer.msg(res.msg);
			if (res.status == 1) {
				reload();
			}
		});
    })
    // 对单
    $("#dd").click(function () {
      	var ids = $("#grid").jqGrid('getGridParam','selarrrow');

		if (ids == '' || ids == null) {
			layer.msg('请先选择需要操作的项！');
			return false;
		}
		//获取商品信息
		$.post('dd.html', { ids: ids,type:1 }, function (res) {
			layer.msg(res.msg);
			if (res.status == 1) {
				reload();
			}
		});
    })

    // 撤销对单
    $("#redd").click(function () {
    	var ids = $("#grid").jqGrid('getGridParam','selarrrow');
      	if (ids == '' || ids == null) {
			layer.msg('请先选择需要操作的项！');
			return false;
		}
		//获取商品信息
		$.post('dd.html', { ids: ids,type:2 }, function (res) {
			layer.msg(res.msg);
			if (res.status == 1) {
				reload();
			}
		});
    })

    // 删除订单
    $("#del").click(function () {
    	//alert("111");
    	var ids = $("#grid").jqGrid('getGridParam','selarrrow');
      	if (ids == '' || ids == null) {
			layer.msg('请先选择需要删除的项！');
			return false;
		}
		//获取商品信息
		$.post('del.html', { ids: ids}, function (res) {
			layer.msg(res.msg);
			if (res.status == 1) {
				reload();
			}
		});
    })

    
});
</script>


{include file="admin@public/footer"/}